import * as Cesium from 'cesium'
export class MousePostion {
    constructor(viewer){
        // 监听鼠标移动事件
        const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas)
        
        handler.setInputAction((mouset) => {
            // 三维坐标
            const cartesian = viewer.camera.pickEllipsoid(mouset.endPosition,viewer.scene.globe.ellipsoid)

            if (cartesian) {
                const cartographic = Cesium.Cartographic.fromCartesian(cartesian)
                const longitude = Cesium.Math.toDegrees(cartographic.longitude).toFixed(2)
                const latitude = Cesium.Math.toDegrees(cartographic.latitude).toFixed(2)
                const height = cartographic.height
                // console.log(`经度：${longitude} 纬度：${latitude} 高度：${height}`)
                document.getElementById('mouse-position').innerHTML = `经度：${longitude} 纬度：${latitude}`
            }
        },Cesium.ScreenSpaceEventType.MOUSE_MOVE)
    }
}